package com.wpw.dream.thread;

import java.lang.Thread.State;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ThreadNote {
	
	public void demo() {
		try {
			wait();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		notify();//或者notifyAll();
		
	}

	public static void main(String[] args) {
		String line = "其中力拓、BHPB和FMG发往中国量分别为584.9增104.6、482.8增85.3、240.9减71.4。";
		List<String> l = new ArrayList<>();
		Pattern pattern = Pattern.compile("\\d+\\.\\d+|\\d+");
		Matcher matcher = pattern.matcher(line);
		String s = "";
		while (matcher.find()) {
			s = matcher.group(0);
			l.add(s);
		}
		System.out.println(l);
		State blocked = Thread.State.BLOCKED;
		try {
			Thread thread = new Thread();
			thread.join();
			thread.getId();
			thread.getName();
			thread.getPriority();
			thread.getState();

			thread.isInterrupted();
			thread.interrupt();
			Thread.interrupted();

			Thread.currentThread().interrupt();

			ThreadLocal<String> a = new ThreadLocal<>();
			a.set("aa");
			System.out.println(a.get());
			
			ThreadGroup tg = new ThreadGroup("groupName");
			tg.list();
			
			Executors.newCachedThreadPool();
			
			Object o = new Object();
			
			ReentrantReadWriteLock wrLock = new ReentrantReadWriteLock();
			wrLock.writeLock().lock();
			Condition wCondition = wrLock.writeLock().newCondition();
			wCondition.await();
			wCondition.signal();//或者signalAll();
			wrLock.writeLock().unlock();
			
			wrLock.readLock().lock();
			Condition rCondition = wrLock.readLock().newCondition();
			rCondition.await();
			rCondition.signal();
			rCondition.signalAll();
			wrLock.readLock().unlock();
			
			
			Lock lock = new ReentrantLock();
			lock.lock();
			
			Condition condition = lock.newCondition();
			condition.await();
//			condition.awaitUntil(deadline);
//			condition.awaitUninterruptibly();
			condition.signal();//或者signalAll();
			
			lock.unlock();
			
			Semaphore sp = new Semaphore(5,true);
			sp.acquireUninterruptibly();
			sp.tryAcquire();
			
			CountDownLatch cdl = new CountDownLatch(3);

		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
